/**
 * 
 */
package org.apache.struts2.gtgrid.components;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.UIBean;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * gt-grid head render
 * 
 * @author Stevie
 * @since 2009-11-30
 * @version 1.0
 * 
 */
public class Head extends UIBean {
	public static final String TEMPLATE = "gtgrid_head";

	private String gtGridCss = "gt_grid.css";
	private boolean debug;
	private String locale;

	public Head(ValueStack stack, HttpServletRequest request,
			HttpServletResponse response) {
		super(stack, request, response);
	}

	protected String getDefaultTemplate() {
		return TEMPLATE;
	}
	
    @Override
    public String getTheme() {
        return "ajax";
    }
    
	public void evaluateParams() {
		super.evaluateParams();

		if (gtGridCss != null) {
			String css = findString(gtGridCss);
			if (css != null && css.trim().length() > 0) {
				if (css.lastIndexOf(".css") < 0) {
					addParameter("gtgridcss", css + ".css");
				} else {
					addParameter("gtgridcss", css);
				}
			}
		}
        if (this.locale != null)
            addParameter("locale", findString(this.locale));
        
		addParameter("encoding", "UTF-8");
		addParameter("debug", Boolean.valueOf(debug).toString());
	}

	public boolean isDebug() {
		return debug;
	}

	public String getGtGridCss() {
		return gtGridCss;
	}

	/**
	 * The gt-grid css theme to use" default="gt_grid.css
	 * 
	 * @ww.tagattribute required="false"
	 */
	public void setGtGridCss(String gtGridCss) {
		this.gtGridCss = gtGridCss;
	}

	/**
	 * Set to true to enable debugging mode for AJAX themes
	 * 
	 * @ww.tagattribute required="false"
	 */
	public void setDebug(boolean debug) {
		this.debug = debug;
	}
	
	/**
	 * set to locale
	 * @param locale
	 */
    public void setLocale(String locale) {
        this.locale = locale;
    }

	public String getLocale() {
		return locale;
	}
    
    
}
